Skip to content

Update collect to take input with specified format#130

Open
davidallendj wants to merge 19 commits into
mainfrom
allend/collect-json-input
Open

Update collect to take input with specified format#130
davidallendj wants to merge 19 commits into
mainfrom
allend/collect-json-input

Conversation

@davidallendj
Copy link
Copy Markdown
Collaborator

@davidallendj davidallendj commented Apr 6, 2026

Pull Request Template

Thank you for your contribution! Please ensure the following before submitting:

Checklist

  • My code follows the style guidelines of this project
  • I have added/updated comments where needed
  • I have added tests that prove my fix is effective or my feature works
  • I have run make test (or equivalent) locally and all tests pass
  • DCO Sign-off: All commits are signed off (git commit -s) with my real name and email
  • [] REUSE Compliance:
    • Each new/modified source file has SPDX copyright and license headers
    • Any non-commentable files include a <filename>.license sidecar
    • All referenced licenses are present in the LICENSES/ directory

Description

This PR changes the collect command to take JSON or YAML as input from the scan command. This allows for the entire discovery process to be completed as a single command without hitting the file system.

Examples:

# scan -> collect
magellan scan --subnet 172.18.0.0/24 --port 5000 -l info -i -F json | magellan collect -f json --show-output -i

# scan -> collect -> send
magellan scan --subnet 172.18.0.0/24 --port 5000 -l info -i -F json | magellan collect -f json --show-output -i | magellan send https://smd.example.com

# collect -> send
magellan collect pdu x3000m0 x3000m1 -u admin -p password | magellan send https://smd.example.com

Fixes #128

Type of Change

  • Bug fix
  • New feature
  • Breaking change
  • Documentation update

For more info, see Contributing Guidelines.

Signed-off-by: David Allen <davidallendj@gmail.com>
Signed-off-by: David Allen <davidallendj@gmail.com>
Signed-off-by: David Allen <davidallendj@gmail.com>
Signed-off-by: David Allen <davidallendj@gmail.com>
Signed-off-by: David Allen <davidallendj@gmail.com>
Signed-off-by: David Allen <davidallendj@gmail.com>
Signed-off-by: David Allen <davidallendj@gmail.com>
Signed-off-by: David Allen <davidallendj@gmail.com>
Signed-off-by: David Allen <davidallendj@gmail.com>
Signed-off-by: David Allen <davidallendj@gmail.com>
@davidallendj davidallendj force-pushed the allend/collect-json-input branch from e59ee6e to 92bdb3b Compare April 6, 2026 22:24
Signed-off-by: David Allen <davidallendj@gmail.com>
Copy link
Copy Markdown
Contributor

@synackd synackd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Testing with real BMCs.

Scanning:

$ ./magellan scan --subnet 172.16.0.0/24 -l info -i -F json --insecure
{"level":"warn","error":"RegisterFlagCompletionFunc: flag 'format' does not exist","time":"2026-05-14T13:45:41-06:00","message":"failed to register completion function"}
[
  {
    "host": "https://172.16.0.105",
    "port": 443,
    "protocol": "tcp",
    "state": true,
    "timestamp": "2026-05-14T13:45:41.948173759-06:00",
    "service_type": "Redfish"
  },
  {
    "host": "https://172.16.0.104",
    "port": 443,
    "protocol": "tcp",
    "state": true,
    "timestamp": "2026-05-14T13:45:41.947999177-06:00",
    "service_type": "Redfish"
  },
  {
    "host": "https://172.16.0.102",
    "port": 443,
    "protocol": "tcp",
    "state": true,
    "timestamp": "2026-05-14T13:45:41.947644981-06:00",
    "service_type": "Redfish"
  },
  {
    "host": "https://172.16.0.101",
    "port": 443,
    "protocol": "tcp",
    "state": true,
    "timestamp": "2026-05-14T13:45:41.947476248-06:00",
    "service_type": "Redfish"
  },
  {
    "host": "https://172.16.0.103",
    "port": 443,
    "protocol": "tcp",
    "state": true,
    "timestamp": "2026-05-14T13:45:41.947691662-06:00",
    "service_type": "Redfish"
  },
  {
    "host": "https://172.16.0.199",
    "port": 443,
    "protocol": "tcp",
    "state": true,
    "timestamp": "2026-05-14T13:45:41.948031377-06:00",
    "service_type": "Redfish"
  },
  {
    "host": "https://172.16.0.198",
    "port": 443,
    "protocol": "tcp",
    "state": true,
    "timestamp": "2026-05-14T13:45:41.947765703-06:00",
    "service_type": "Redfish"
  }
]

Scanning piping to collect:

$ ./magellan scan --subnet 172.16.0.0/24 -l info -i -F json --insecure | ./magellan collect -f json --show-output -i
{"level":"warn","error":"RegisterFlagCompletionFunc: flag 'format' does not exist","time":"2026-05-14T13:46:07-06:00","message":"failed to register completion function"}
{"level":"warn","error":"RegisterFlagCompletionFunc: flag 'format' does not exist","time":"2026-05-14T13:46:07-06:00","message":"failed to register completion function"}
{"level":"error","error":"no file found","time":"2026-05-14T13:46:07-06:00","caller":"/opt/shared/magellan/cmd/collect.go:61","message":"failed to get scanned results from cache"}
{"level":"error","error":"no assets found","time":"2026-05-14T13:46:07-06:00","caller":"/opt/shared/magellan/cmd/collect.go:178","message":"failed to collect data"}
null

Comment thread cmd/collect.go
@@ -9,16 +9,20 @@ import (
"github.com/OpenCHAMI/magellan/internal/cache/sqlite"
"github.com/OpenCHAMI/magellan/internal/format"
magellan "github.com/OpenCHAMI/magellan/pkg"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we haven't added linting to Magellan yet, we definitely should. Internal imports should go after other package imports. I suspect this needs to be done in other files as well, so it can be addressed in a subsequent PR.

@davidallendj
Copy link
Copy Markdown
Collaborator Author

Testing with real BMCs.

Scanning:

$ ./magellan scan --subnet 172.16.0.0/24 -l info -i -F json --insecure
{"level":"warn","error":"RegisterFlagCompletionFunc: flag 'format' does not exist","time":"2026-05-14T13:45:41-06:00","message":"failed to register completion function"}
[
  {
    "host": "https://172.16.0.105",
    "port": 443,
    "protocol": "tcp",
    "state": true,
    "timestamp": "2026-05-14T13:45:41.948173759-06:00",
    "service_type": "Redfish"
  },
  {
    "host": "https://172.16.0.104",
    "port": 443,
    "protocol": "tcp",
    "state": true,
    "timestamp": "2026-05-14T13:45:41.947999177-06:00",
    "service_type": "Redfish"
  },
  {
    "host": "https://172.16.0.102",
    "port": 443,
    "protocol": "tcp",
    "state": true,
    "timestamp": "2026-05-14T13:45:41.947644981-06:00",
    "service_type": "Redfish"
  },
  {
    "host": "https://172.16.0.101",
    "port": 443,
    "protocol": "tcp",
    "state": true,
    "timestamp": "2026-05-14T13:45:41.947476248-06:00",
    "service_type": "Redfish"
  },
  {
    "host": "https://172.16.0.103",
    "port": 443,
    "protocol": "tcp",
    "state": true,
    "timestamp": "2026-05-14T13:45:41.947691662-06:00",
    "service_type": "Redfish"
  },
  {
    "host": "https://172.16.0.199",
    "port": 443,
    "protocol": "tcp",
    "state": true,
    "timestamp": "2026-05-14T13:45:41.948031377-06:00",
    "service_type": "Redfish"
  },
  {
    "host": "https://172.16.0.198",
    "port": 443,
    "protocol": "tcp",
    "state": true,
    "timestamp": "2026-05-14T13:45:41.947765703-06:00",
    "service_type": "Redfish"
  }
]

Scanning piping to collect:

$ ./magellan scan --subnet 172.16.0.0/24 -l info -i -F json --insecure | ./magellan collect -f json --show-output -i
{"level":"warn","error":"RegisterFlagCompletionFunc: flag 'format' does not exist","time":"2026-05-14T13:46:07-06:00","message":"failed to register completion function"}
{"level":"warn","error":"RegisterFlagCompletionFunc: flag 'format' does not exist","time":"2026-05-14T13:46:07-06:00","message":"failed to register completion function"}
{"level":"error","error":"no file found","time":"2026-05-14T13:46:07-06:00","caller":"/opt/shared/magellan/cmd/collect.go:61","message":"failed to get scanned results from cache"}
{"level":"error","error":"no assets found","time":"2026-05-14T13:46:07-06:00","caller":"/opt/shared/magellan/cmd/collect.go:178","message":"failed to collect data"}
null

I think this may be happening because the --cache-path flag is set to a non-empty string by default.

This is where the check happens:
https://github.com/OpenCHAMI/magellan/blob/allend/collect-json-input/cmd/collect.go#L58

And here is where the flag default is set:
https://github.com/OpenCHAMI/magellan/blob/allend/collect-json-input/cmd/root.go#L93

I can run it by setting --cache "" but I'm running to another problem that I'm working to address.

./magellan scan --subnet 172.16.0.0/24 -l info -i -F json | ./magellan collect -f json --show-output -i --cache "" -l debug

Signed-off-by: David Allen <davidallendj@gmail.com>
Signed-off-by: David Allen <davidallendj@gmail.com>
Signed-off-by: David Allen <davidallendj@gmail.com>
Signed-off-by: David Allen <davidallendj@gmail.com>
@davidallendj davidallendj force-pushed the allend/collect-json-input branch from cbe75b6 to 7b1e8d4 Compare June 1, 2026 20:32
Signed-off-by: David Allen <davidallendj@gmail.com>
Signed-off-by: David Allen <davidallendj@gmail.com>
Signed-off-by: David Allen <davidallendj@gmail.com>
Signed-off-by: David Allen <davidallendj@gmail.com>
@davidallendj
Copy link
Copy Markdown
Collaborator Author

@synackd It should be working now. I had to add some missing logic back to cmd/collect.go and update some of the CLI flags. I don't think I like having to explicitly set --cache "" for this to work though...

This is the command I'm using to test currently:

./magellan scan --subnet 172.16.0.0/24 -l info -i -F json | ./magellan collect -f json --show-output -i --cache "" -l debug

@synackd
Copy link
Copy Markdown
Contributor

synackd commented Jun 1, 2026

That command line worked for me. What if we added a check to see that stdin was open and, if so, used that instead of a cache unless explicitly told to do so?

@synackd synackd changed the title Update collect take input with specified format Update collect take input with specified format Jun 1, 2026
@synackd synackd changed the title Update collect take input with specified format Update collect to take input with specified format Jun 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature]: Allow collect to take JSON or YAML as input

2 participants